#include "dominion.h"
#include "dominion_helpers.h"
#include "rngs.h"
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>

//randomtestcard.c - steward

/*

int initializeGame(int numPlayers, int kingdomCards[10], int randomSeed,
		   struct gameState *state)

int cardEffect(int card, int choice1, int choice2, int choice3, struct gameState *state, int handPos, int *bonus)

    case steward:
		if (choice1 == 1) {
			//+2 cards
			drawCard(currentPlayer, state);
			drawCard(currentPlayer, state);
		}
		else if (choice1 == 2) {
			//+2 coins
			state->coins = state->coins + 2;
		}
		else {
			//trash 2 cards in hand
			discardCard(choice2, currentPlayer, state, 1);
			discardCard(choice3, currentPlayer, state, 1);
		}
			
		//discard card from hand
		discardCard(handPos, currentPlayer, state, 0);
		return 0;
		
*/

void randomtest_steward() {
	srand(time(NULL));

	int numPlayers = 4;
	int kingdomCards[10];
	
	for (int i = 0; i < 10; ++i) {
		kingdomCards[i] = (rand() % treasure_map-adventurer) + adventurer;
	}
	
	int randomSeed = rand();
	
	struct gameState *state = malloc(sizeof(struct gameState));
	
	for (int i = 0; i < numPlayers; ++i) {
		state->handCount[i] = 5;
		for (int j = 0; j < 5; ++j) {
			state->hand[i][j] = kingdomCards[rand() % 10];
		}
	}
	
	initializeGame(numPlayers, kingdomCards, randomSeed, state);
	
	struct gameState *state2 = malloc(sizeof(struct gameState));
	
	int MAX_TEST = 10000;
	for (int i = 0; i < MAX_TEST; ++i) {
		
		int currentPlayer = (rand() % 4);
		state->whoseTurn = currentPlayer;
		
		int choice1 = (rand() % 3) + 1;
		int choice2 = (rand() % 4);
		int choice3 = (rand() % 4);
		
		memcpy(state2, state, sizeof(struct gameState));
	
		//play steward card
		cardEffect(steward, choice1, choice2, choice3, state2, 3, 0);
		
		if (choice1 == 1) {
			if (state->handCount[currentPlayer]+2 == state2->handCount[currentPlayer]) {
				printf("PASS: drawing 2 cards\n");
			}
			else {
				printf("FAIL: drawing 2 cards\n");
			}
		}
		else if (choice1 == 2) {
			if (state->coins+2 == state2->coins) {
				printf("PASS: adding 2 coins\n");
			}
			else {
				printf("FAIL: adding 2 coins\n");
			}
		}
		else {
			if (state->handCount[currentPlayer]-2 == state2->handCount[currentPlayer]) {
				printf("PASS: trashing 2 cards\n");
			}
			else {
				printf("FAIL: trashing 2 cards\n");
			}
		}
	}
}

int main() {
	randomtest_steward();
}
